home *** CD-ROM | disk | FTP | other *** search
- #ifndef _DECL_H
- #define _DECL_H 1
-
- /**************************************************************************
- * decl.h: Miscellaneous global declarations.
- * A part of OberSuite for the Commodore Amiga.
- *
- * Author: Daniel Barrett, barrett@cs.umass.edu.
- * Version: 1.0.
- * Copyright: None! This program is in the Public Domain.
- * Please share it with others.
- ***************************************************************************/
-
- #include <exec/types.h>
- #include <exec/ports.h>
- #include <exec/devices.h>
- #include <exec/memory.h>
- #include <exec/interrupts.h>
- #include <devices/serial.h>
- #include <libraries/dos.h>
- #include <libraries/dosextens.h>
- #include <stdio.h>
- #include <stdlib.h> /* getenv */
- #include <string.h>
- #include <ctype.h>
- #include <fcntl.h>
- #include <stat.h>
- #include <functions.h>
- #include "bits.h"
- #include "midi.h"
- #include "oberheim.h"
- #include "patchinfo.h"
-
- /***************************************************************************
- * Macros for patch numbers.
- ***************************************************************************/
-
- #define LETTER_SINGLE 'S' /* Indicates a single patch. */
- #define LETTER_MULTI 'M' /* Indicates a multi patch. */
- #define ALL_PATCHES_NUM 100 /* All patches should be sent. */
- #define DEFAULT_PATCH_NUM 100 /* An impossible patch number value,
- * indicating that a default should
- * be used.
- */
-
- #define MODE_SINGLE 0x00 /* Byte indicating a single patch. */
- #define MODE_MULTI 0x01 /* Byte indicating a multi patch. */
-
- /***************************************************************************
- * Macros for signalling that a transfer has failed.
- ***************************************************************************/
-
- #define NUM_RETRIES 10 /* Max number of retransmissions. */
- #define CTRL_C_NO_BYTES (-1) /* User pressed ^C. */
-
- /***************************************************************************
- * Highlighting for the output -- for making certain words more noticable.
- ***************************************************************************/
-
- #define HILITE_ON "\x9b" "2m"
- #define HILITE_OFF "\x9b" "22m"
-
- /***************************************************************************
- * Miscellaneous macros.
- ***************************************************************************/
-
- #define EXISTS(filename) !access(filename, 0)
- #define EQUAL !strcmp
-
- /***************************************************************************
- * The name of the (optional) environment variable containing the name and
- * unit number of an alternate MIDI device.
- ***************************************************************************/
-
- #define ENVIRONMENT_VAR "OBERHEIM_DEVICE"
-
- /***************************************************************************
- * Author information.
- ***************************************************************************/
-
- #define AUTHOR "Daniel J. Barrett"
-
- /***************************************************************************
- * Error message codes.
- ***************************************************************************/
-
- #define ERROR_PATCHNUM 1
- #define ERROR_PATCHTYPE 2
- #define ERROR_NUMARGS 3
- #define ERROR_FAILED 4
- #define ERROR_FINDFILE 5
- #define ERROR_CREATEFILE 6
- #define ERROR_READFILE 7
- #define ERROR_WRITEFILE 8
- #define ERROR_FILESIZE 9
- #define ERROR_FILEGARBLED 10
- #define ERROR_CTRLC 11
- #define ERROR_GETFAILED 12
- #define ERROR_PUTFAILED_SAVE 13
- #define ERROR_NOTSYSEX 14
- #define ERROR_NOTOBERHEIM 15
- #define ERROR_NOTXPMATRIX 16
- #define ERROR_NOTPATCHDATA 17
- #define ERROR_UNKNOWNVOICEDATA 18
- #define ERROR_NOEOX 19
- #define ERROR_DATATOOBIG 20
- #define ERROR_DATATOOSMALL 21
- #define ERROR_CREATEPORT 22
- #define ERROR_IOEXTSER 23
- #define ERROR_OPENDEVICE 24
- #define ERROR_SETPARAMS 25
- #define ERROR_OBDEVICE 26
- #define ERROR_OBUNIT 27
- #define ERROR_MALLOC 28
- #define ERROR_TWOPRINTS 29
- #define ERROR_NODEST 30
- #define ERROR_PUTFAILED_SEND 31
- #define ERROR_REALNAMESFILEONLY 32
- #define ERROR_OVERWRITEFILEONLY 33
-
- #define NO_MESSAGE ((char *)NULL)
-
- /***************************************************************************
- * Global variables.
- ***************************************************************************/
-
- char programName[BUFSIZ]; /* The name of the program (argv[0]). */
- extern int Enable_Abort; /* To disable Aztec ^C handling. */
-
- /***************************************************************************
- * Printing style for the output.
- * DEADQUIET must be less than SILENT, and SILENT must be less than
- * every other print style.
- ***************************************************************************/
-
- int thePrintStyle;
- #define DEADQUIET 0 /* No output; not even error messages. */
- #define SILENT 1 /* No output, except for error messages. */
- #define SHORT 2 /* Brief output. */
- #define PRETTY 3 /* Nice-looking output. */
- #define VERBOSE 4 /* Long output. */
-
- #define OUTPUT_ALLOWED (thePrintStyle > SILENT)
- #define ERR_OUTPUT_ALLOWED (thePrintStyle > DEADQUIET)
-
- /***************************************************************************
- * Command-line options.
- ***************************************************************************/
-
- #define OPT_DEADQUIET 'Q' /* No output; not even error messages. */
- #define OPT_SILENT 'q' /* No output; error messages still print. */
- #define OPT_SHORT 's' /* Brief output. */
- #define OPT_PRETTY 'm' /* Nice-looking output. */
- #define OPT_VERBOSE 'l' /* Long output. */
-
- #define OPT_OVERWRITE 'a' /* Silently overwrite existing files. */
-
- #define OPT_SYNTH 'o' /* Send data to the Oberheim. */
- #define OPT_FILE 'f' /* Send data to a file. */
-
- #define OPT_USEREALNAMES 'r' /* Use patch names as output file names. */
-
-
- /* For getopt(). */
- extern char *optarg;
- extern int optind;
-
- /***************************************************************************
- * Where is the MIDI data going?
- ***************************************************************************/
-
- #define DEST_NONE 0 /* Data is going nowhere. */
- #define DEST_SYNTH 1 /* Data is being sent to the synth. */
- #define DEST_FILE 2 /* Data is going to a file. */
-
- /***************************************************************************
- * Prototypes.
- ***************************************************************************/
-
- char *Version(void);
- void Usage(void);
- void UsageMsg(void);
- void ShortUsageMsg(void);
- void DetailedUsage(void);
- void BegForUsage(void);
- void Author(void);
- void ErrorMsg(int code);
-
- BOOL AllDigits(char *str);
- int Between(int value, int low, int high);
- BOOL SameSoFar(char *start, char *wholeThing);
- char *LeadingZero(int num);
- void PrintSynthType(int patchType, int multiData, FILE *fp);
- void PrintPatchType(int patchType, FILE *fp);
-
- BOOL SerialSetup(void);
- void SerialShutdown(void);
- void ResetSerialPort(void);
- void PrepareToReadMidi(UBYTE buf[], int len);
- void PrepareToWriteMidi(UBYTE buf[], int len);
- long AnyMidiData(void);
- long DoTheIO(void);
-
- int GetOnePatch(UBYTE num, int mode, int fd);
- int GetAllPatches(int mode, int fd);
- void RequestOnePatch(UBYTE patchNum, int mode);
- BOOL DoTheRightThing(int bytesRead, int expectedSize, int numTries,
- int fd, UBYTE buf[]);
-
- BOOL DontOverwriteExistingFile(char *filename);
- int OpenReadFile(char *filename);
- int OpenWriteFile(char *filename);
- long FileSize(char *filename);
-
- int AddToRange(BITS bitfield[], int first, int second);
- int MakeRange(char *str, int *first, int *second);
-
-
- BOOL BreakUp(char *patchString, PATCHINFO *pi);
- BOOL FigureOutMode(PATCHINFO *pi, char modeLetter);
- BOOL FigureOutPatchNumber(PATCHINFO *pi, char *numString);
-
- void EnableRequestors(void);
- void DisableRequestors(void);
- char *TheEnvValue(BPTR fileHandle);
- char *GetEnv(char *variableName);
- BOOL CtrlcCheck(void);
- char *BaseName(char *filename);
-
- BOOL HandleOptions(int argc, char *argv[]);
-
-
- void InitPatchInfo(PATCHINFO *pi);
- void PrintPatchInfo(PATCHINFO *pi, long offset);
- void PrintPatchName(UBYTE *patch, long startHere);
- void PrintSinglesInMulti(UBYTE *patch, long howMany, long startHere);
- void FreePatchInfo(PATCHINFO *pi);
- BOOL TransmitPatchInfo(PATCHINFO *pi, char *filename);
- BOOL GetPatchFromFile(PATCHINFO *pi, char *filename);
- BOOL GetPatchFromMidi(PATCHINFO *pi);
- long GetFromMidi(PATCHINFO *pi, long offset);
- BOOL PutPatchToFile(PATCHINFO *pi, char *filename);
- BOOL PutPatchToMidi(PATCHINFO *pi);
- BOOL RepeatedlySend(PATCHINFO *pi);
- void PutToMidi(PATCHINFO *pi, long offset);
- void AdjustPatchNumber(PATCHINFO *pi);
- BOOL VerifyPatch(PATCHINFO *pi, long offset);
- BOOL VerifyAllPatches(PATCHINFO *pi);
- BOOL FigureOutInstrument(PATCHINFO *pi, UBYTE instrument);
- BOOL FigureThingsOutFromHeader(PATCHINFO *pi);
- void RequestTheRightPatch(PATCHINFO *pi, int relativeNum);
- char *fgets_and_flush(char *buf, int length, FILE *fp);
-
-
- #endif /* _DECL_H */
-